package com.dianning.web.action;

import java.util.List;

import org.apache.commons.logging.*;

import com.dianning.bean.Area;
import com.dianning.bean.Channel;
import com.dianning.bean.ChannelContact;
import com.dianning.bean.Info;
import com.dianning.bean.Visitor;
import com.dianning.service.AreaService;
import com.dianning.service.ChannelService;
import com.dianning.service.InfoService;
import com.dianning.service.VisitorService;

public class Post extends BaseAction{

	private static final Log logger = LogFactory.getLog(Post.class);

	private ChannelService channelService;
	private AreaService areaService;
	private InfoService infoService;

	public ChannelService getChannelService() {
		return channelService;
	}

	public void setChannelService(ChannelService channelService) {
		this.channelService = channelService;
	}

	public AreaService getAreaService() {
		return areaService;
	}

	public void setAreaService(AreaService areaService) {
		this.areaService = areaService;
	}

	public InfoService getInfoService() {
		return infoService;
	}

	public void setInfoService(InfoService infoService) {
		this.infoService = infoService;
	}
	
	private List options;
	private ChannelContact bigChannel;
	private ChannelContact smallChannel;
	private Channel channel;
	private Area area;
	private Info info;
	
	public List getOptions() {
		return options;
	}

	public void setOptions(List options) {
		this.options = options;
	}
	
	public ChannelContact getBigChannel() {
		return bigChannel;
	}

	public void setBigChannel(ChannelContact bigChannel) {
		this.bigChannel = bigChannel;
	}

	public ChannelContact getSmallChannel() {
		return smallChannel;
	}

	public void setSmallChannel(ChannelContact smallChannel) {
		this.smallChannel = smallChannel;
	}

	public Channel getChannel() {
		return channel;
	}

	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public Info getInfo() {
		return info;
	}

	public void setInfo(Info info) {
		this.info = info;
	}

	
	private long id;
	private long bid;
	private long sid;
	private long areaId;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getBid() {
		return bid;
	}

	public void setBid(long bid) {
		this.bid = bid;
	}

	public long getSid() {
		return sid;
	}

	public void setSid(long sid) {
		this.sid = sid;
	}public long getAreaId() {
		return areaId;
	}

	public void setAreaId(long areaId) {
		this.areaId = areaId;
	}


	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return ERROR;
		}
	}
	
	public String index(){
		this.setOptions(this.getChannelService().findChannelContacts(-1, 1, "orders", 0));
		return "channel";
	}
	
	public String smallChannel(){
		this.setBigChannel(this.getChannelService().findChannelContactById(this.bid));
		this.setOptions(this.getChannelService().findChannelContacts(this.bid, 2, "orders", 0));
		return "smallChannel";
	}

	public String area(){
		this.setBigChannel(this.getChannelService().findChannelContactById(this.bid));
		this.setSmallChannel(this.getChannelService().findChannelContactById(this.sid));
		this.setOptions(this.getAreaService().findAreas("orders", 0));
		return "area";
	}

	public String tradingArea(){
		this.setBigChannel(this.getChannelService().findChannelContactById(this.bid));
		this.setSmallChannel(this.getChannelService().findChannelContactById(this.sid));
		this.setArea(this.getAreaService().findAreaById(this.areaId));
		this.setOptions(this.getAreaService().findTradingAreasByAreaId(this.areaId,"orders", 0));
		return "tradingArea";
	}
	
	public String finish(){
		this.setInfo(this.getInfoService().findInfoById(this.id));
		return "finish";
	}
}
